package ssi.staaar.ciphers;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.util.Log;

public class SHA1Digester {
	public static String digestString(String inputString) {
		MessageDigest digester = null;
		try {
			digester = MessageDigest.getInstance("SHA1");
		} catch (NoSuchAlgorithmException e) {
			Log.d("[STAAAR]", "ERROR: Your Java(TM) platform doesn't support SHA1 digest.");
			System.exit(1);
		}
		return from_bytes_to_string(digester.digest(inputString.getBytes()));
	}
	
	public static String from_bytes_to_string (byte [] bytes){
		String retval = "";
		for (int i = 0; i < bytes.length; ++i)
			retval += ((bytes[i] & 0xff) < 16 ? "0" : "") + Integer.toHexString(bytes[i] & 0xff);
		return retval;
	}
}
